package cn.strive.eams.application.service.impl;

import cn.strive.eams.application.mapper.ApplicationMapper;
import cn.strive.eams.application.pojo.dto.ApplicationQuery;
import cn.strive.eams.application.pojo.entity.Application;
import cn.strive.eams.application.pojo.vo.ApplicationVO;
import cn.strive.eams.application.service.ApplicationService;
import cn.strive.eams.audit.mapper.AuditMapper;
import cn.strive.eams.base.enmus.ApplicationStatusEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class ApplicationServiceImpl implements ApplicationService {

    @Autowired
    ApplicationMapper applicationMapper;
    @Autowired
    AuditMapper auditMapper;
    @Override
    public List<ApplicationVO> selectAll(ApplicationQuery applicationQuery) {
        log.debug("查询申请列表,参数:{}", applicationQuery);
        return applicationMapper.selectAll(applicationQuery);
    }

    @Override
    public List<ApplicationVO> selectById(Long id) {
       log.debug("查询申请详情:id={}", id);
       return applicationMapper.selectById(id);
    }

    @Override
    public void cancel(Long id) {
        log.debug("取消申请业务:id={}",id);
        Application application = new Application();
        application.setId(id);
        application.setStatus(ApplicationStatusEnum.CANCEL.getCode());
        application.setUpdateTime(new Date());
        applicationMapper.update(application);

        auditMapper.cancel(id);
    }
}
